Japanese Patent Application Publication No. 2016-149715 discloses a semiconductor device in which a switching element and a protection diode are provided in a common semiconductor substrate. A cathode electrode of the protection diode is connected to one of terminals of the switching element. An anode electrode of the protection diode is connected to an external circuit. A potential of the anode electrode of the protection diode varies with a potential of the one terminal of the switching element. A technology in Japanese Patent Application Publication No. 2016-149715 determines whether or not a freewheel diode connected in parallel to the switching element is turned on in accordance with the potential of the anode electrode of the protection diode. When the freewheel diode is turned off, the external circuit permits the switching element to be turned on.